import { Controller } from "../../mvc/core/Controller";
import { DataEvent } from "../events/DataEvent";
import { RecallOldPlayersBtn } from "../view/recallOldPlayers/RecallOldPlayersBtn";
import { RecallOldPlayerActivitiesBtn } from "../view/recallOldPlayers/RecallOldPlayerActivitiesBtn";
import { RecallOldPlayerActivitiesPanel } from "../view/recallOldPlayers/RecallOldPlayerActivitiesPanel";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SFriendCallBack } from "../../../Message/Game/SFriendCallBack";
import { IRecallOldPlayersModule } from "../../../modules/interfaces/IRecallOldPlayersModule";
import { RecallOldPlayersModule } from "../../../modules/RecallOldPlayersModule";
import { SGuildMemberCallBackMsg } from "../../../Message/Game/SGuildMemberCallBackMsg";
import { SGuildMemberCallBack } from "../../../Message/Game/SGuildMemberCallBack";
import { SUpdateMsg } from "../../../Message/Game/SUpdateMsg";
import { Alert } from "../../../com/mui/controls/Alert";
import { Language } from "../../../extend/language/Language";
import { GameProxy } from "../mvc/GameProxy";
import { SActiveToClient } from "../../../Message/Public/SActiveToClient";
import { EActiveType } from "../../../Message/Public/EActiveType";
import { ClockManager } from "../manager/ClockManager";
import { MergeRechargeData } from "../view/consumeCount/MergeRechargeData";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { EPublicCommand } from "../../../Message/Command/EPublicCommand";
import { EGateCommand } from "../../../Message/Command/EGateCommand";
import { ServerCommand } from "../mvc/ServerCommand";
import { IView } from "../../mvc/interfaces/IView";
type int = number;
//class RecallOldPlayersController
    
    export  class RecallOldPlayersController extends Controller
    {
       

        /* internal  */onModuleShowHandler(arg1: DataEvent): void
        {
            view.show();
            return;
        }

        /* internal  */get recallOldPlayersBtn(): RecallOldPlayersBtn
        {
            if (this._recallOldPlayersBtn == null) 
            {
                this._recallOldPlayersBtn = new RecallOldPlayersBtn();
            }
            return this._recallOldPlayersBtn;
        }

        /* internal  */get activitiesBtn(): RecallOldPlayerActivitiesBtn
        {
            if (this._activitiesBtn == null) 
            {
                this._activitiesBtn = new RecallOldPlayerActivitiesBtn();
            }
            return this._activitiesBtn;
        }

        /* internal  */get activitiesPanel(): RecallOldPlayerActivitiesPanel
        {
            if (this._activitiesPanel == null) 
            {
                this._activitiesPanel = new RecallOldPlayerActivitiesPanel();
            }
            return this._activitiesPanel;
        }

        /* internal  */onFriendCallBackListHandler(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SFriendCallBack;
            if (loc1) 
            {
                cache.recallOldPlayers.getFriendRecallIdList(loc1.list);
                cache.recallOldPlayers.getFriendRecallList();
                IRecallOldPlayersModule(view).showRecallView(cache.recallOldPlayers.friendRecallData, RecallOldPlayersModule.FRIEND_RECALL);
            }
            return;
        }

        /* internal  */onGuildCallBackListHandler(arg1: MessageBlock): void
        {
            var loc2=0;
            var loc3=null;
            var loc4=null;
            var loc1=arg1.messageBase as SGuildMemberCallBackMsg;
            if (loc1) 
            {
                loc2 = 0;
                loc3 = "";
                var loc5=0;
                var loc6=loc1.comeBackMembers;
                for(loc4 of loc6) 
                {
                    ++loc2;
                    if (loc2 == 1) 
                    {
                        loc3 = loc3 + loc4;
                        continue;
                    }
                    loc3 = loc3 + ("、" + loc4);
                }
                loc1.list.sort(this.leagueRecallDataSort);
                cache.recallOldPlayers.leagueRecallData = loc1.list;
                IRecallOldPlayersModule(view).setReturnLeagueMember(loc2, loc3);
                IRecallOldPlayersModule(view).showRecallView(cache.recallOldPlayers.leagueRecallData, RecallOldPlayersModule.LEAGUE_RECALL);
            }
            return;
        }

        /* internal  */leagueRecallDataSort(arg1: SGuildMemberCallBack, arg2: SGuildMemberCallBack): int
        {
            if (arg1.member.level > arg2.member.level) 
            {
                return -1;
            }
            if (arg1.member.level < arg2.member.level) 
            {
                return 1;
            }
            return 0;
        }

        /* internal  */onComeBackExpGiving(arg1: MessageBlock): void
        {
            var mb: MessageBlock;
            var info: SUpdateMsg;
            var onClickHandler: Function;

            var loc1;
            onClickHandler = null;
            mb = arg1;
            onClickHandler = (arg1: int): void
            {
                if (arg1 == Alert.OK) 
                {
                    Alert.resetToDefault();
                }
                return;
            }
            info = mb.messageBase as SUpdateMsg;
            Alert.show(Language.getStringByParam(27761, info.value), null, Alert.OK, null, onClickHandler);
            return;
        }

        /* internal  */onComeBackPlayerExpAdd(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SUpdateMsg;
            cache.recallOldPlayers.oldPlayersExpAddPercent = loc1.value;
            return;
        }

        /* internal  */onGetFriendRecallListHandler(arg1: DataEvent): void
        {
            GameProxy.recallOldPlayers.getFriendRecallList();
            GameProxy.recallOldPlayers.getFriendBindInfo();
            return;
        }

        /* internal  */onGetLeagueRecallListHandler(arg1: DataEvent): void
        {
            GameProxy.recallOldPlayers.getLeagueRecallList();
            return;
        }

        /* internal  */onBindFriendHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data.palyerId;
            GameProxy.recallOldPlayers.bindFriend(loc1);
            return;
        }

        /* internal  */onBindFriendSucess(arg1: DataEvent): void
        {
            var loc1=arg1.data.palyerId;
            cache.recallOldPlayers.setIsRecall(loc1);
            cache.recallOldPlayers.getFriendRecallList();
            IRecallOldPlayersModule(view).showRecallView(cache.recallOldPlayers.friendRecallData, RecallOldPlayersModule.FRIEND_RECALL);
            return;
        }

        /* internal  */onRecallOldPlayerActivitiesPanelShowHandler(arg1: DataEvent): void
        {
            this.activitiesPanel.show();
            return;
        }

        /* internal  */onGetFriendBindInfoSucess(arg1: DataEvent): void
        {
            var loc2=null;
            var loc1=arg1.data.dic;
            var loc3=0;
            var loc4=loc1;
            for (loc2 in loc4) 
            {
                this._playerType = int(loc2);
                this._friendId = loc1[loc2];
                if (int(loc2) == 1) 
                {
                    IRecallOldPlayersModule(view).updateFriendBindInfo(this._playerType, this._friendId);
                    continue;
                }
                GameProxy.recallOldPlayers.getMyCallBackList();
            }
            return;
        }

        /* internal  */onGetMyCallBackListSucess(arg1: DataEvent): void
        {
            var loc2=null;
            var loc1=arg1.data.backList;
            if (loc1) 
            {
                loc2 = cache.recallOldPlayers.getAllComeBackFriendNamesByIds(loc1);
                IRecallOldPlayersModule(view).updateFriendBindInfo(this._playerType, this._friendId, loc2, loc1.length);
            }
            return;
        }

        /* internal  */onAcitveTimeUpdateHandler(arg1: SActiveToClient): void
        {
            var loc1=cache.active.isActiveInEffect(EActiveType._EActiveTypeOldPlayerCallBack);
            if (arg1.code != EActiveType._EActiveTypeCallBackExpGiving) 
            {
            };
            if (loc1) 
            {
                if (this.activitiesBtn.isHide) 
                {
                    this.activitiesBtn.show();
                }
                if (this.recallOldPlayersBtn.isHide) 
                {
                    this.recallOldPlayersBtn.show();
                }
                ClockManager.instance.addDateCall(arg1.endDt, this.removeMergeRechargeActive);
            }
            return;
        }

        /* internal  */removeMergeRechargeActive(): void
        {
            if (this._activitiesBtn && !this._activitiesBtn.isHide) 
            {
                this.activitiesBtn.hide();
            }
            if (this._recallOldPlayersBtn && !this._recallOldPlayersBtn.isHide) 
            {
                this.recallOldPlayersBtn.hide();
            }
            if (_view && !_view.isHide) 
            {
                _view.hide();
            }
            if (this._activitiesPanel && !this._activitiesPanel.isHide) 
            {
                this._activitiesPanel.hide();
            }
            if (MergeRechargeData.activeToClient) 
            {
                ClockManager.instance.removeDateCall(MergeRechargeData.activeToClient.endDt);
            }
            return;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.RecallOldPlayersModuleShow, this.onModuleShowHandler);
            Dispatcher.addEventListener(EventName.GetFriendRecallList, this.onGetFriendRecallListHandler);
            Dispatcher.addEventListener(EventName.GetLeagueRecallList, this.onGetLeagueRecallListHandler);
            Dispatcher.addEventListener(EventName.GetFriendBindInfoSucess, this.onGetFriendBindInfoSucess);
            Dispatcher.addEventListener(EventName.GetMyCallBackListSucess, this.onGetMyCallBackListSucess);
            Dispatcher.addEventListener(EventName.BindFriend, this.onBindFriendHandler);
            Dispatcher.addEventListener(EventName.BindFriendSucess, this.onBindFriendSucess);
            Dispatcher.addEventListener(EventName.RecallOldPlayerActivitiesPanelShow, this.onRecallOldPlayerActivitiesPanelShowHandler);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicFriendCallBackList, this.onFriendCallBackListHandler);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicGuildCallBackList, this.onGuildCallBackListHandler);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateComeBackPlayerExpAdd, this.onComeBackPlayerExpAdd);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateOldPlayerCallBackExpGiving, this.onComeBackExpGiving);
            NetDispatcher.addCmdListener(ServerCommand.RecallOldPlayerActivitiesInfoCommand, this.onAcitveTimeUpdateHandler);
            return;
        }

        protected /* override */ initView(): IView
        {
            if (this._recallOldPlayersModule == null) 
            {
                this._recallOldPlayersModule = new RecallOldPlayersModule();
            }
            return this._recallOldPlayersModule;
        }

        private /* var */_recallOldPlayersModule: IRecallOldPlayersModule;

        private /* var */_recallOldPlayersBtn: RecallOldPlayersBtn;

        private /* var */_activitiesPanel: RecallOldPlayerActivitiesPanel;

        private /* var */_activitiesBtn: RecallOldPlayerActivitiesBtn;

        private /* var */_playerType: int;

        private /* var */_friendId: int;
    }
